﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading;

namespace libPlugin
{
    public static class pluginManager
    {
        public static List<IBotPlugin> pluginList { get; set; }
        public static List<Thread> threadList { get; set; }

        static pluginManager()
        {
            pluginList = new List<IBotPlugin>();
            threadList = new List<Thread>();

            foreach (FileInfo file in new DirectoryInfo(Directory.GetCurrentDirectory()).GetFiles("*.dll"))
            {
                foreach (Type t in Assembly.LoadFrom(file.FullName).GetTypes())
                {
                    if (t.GetInterface("IBotPlugin") != null)
                    {
                        pluginList.Add((IBotPlugin)t.GetConstructor(new Type[] {}).Invoke(new object[] {}));
                    }
                }
            }

            foreach (IBotPlugin plugin in pluginList)
            {
                threadList.Add(new Thread(plugin.workerMethod));
            }

            foreach (Thread thread in threadList)
            {
                thread.Start();
            }
        }
    }
}
